<?php 

namespace app\bee\controller;
use think\Controller;
use think\Cache;
use \DOMDocument;
use \DateTime;
use \http_get;

header('Origin: http://www.costco.com');

class Costco extends BeeController {
  public function index() {
    if (!isset($_GET['q'])) {
      echo 'please enter q';
      return;
    }
    $url = 'http://www.costco.com/CatalogSearch?storeId=10301&catalogId=10701&langId=-1&keyword=' . $_GET['q'];
    // $url = 'https://www.costco.com/Maidenform-Ladies%27-Comfort-Devotion-Bra-2-pack-Black-%2526-Latte.product.100242123.html?catalogId=10701&catalogId=10701&langId=-1&langId=-1&storeId=10301&storeId=10301&krypto=F%2BBUCniexLJnKFenN1PVnxBbW7PIJogcFQoZPZJz0RwIlmF%2BiTJupGwFvyS52gYNt3KCda2qkzke%0AwIFpxe2CmiqzqDiLc4oKqiojND6vRXI%3D';
    // $url = 'https://www.instacart.com/store/costco/search_v3/contingo';
    $opt['header'] = array(
      'Origin: http://www.costco.com',
      'Set-Cookie: bm_mi=C84AC705F1D4BE9FF2DE8C002F24F81A~giT7PuekVc5ukXhzyvRUHRNJAlbAV/Qwr6mDV69tIFm11fktiB+5cIbPTB6BRh+M0MnlbTMr1G9aVzx/P6ipyrb0Umm5vxxTg1CgUUil7pam4YjExceItMKoAu+qPASpz/pEJdCxcq08Nn49OAFyF91SyeHzNIF59/ptB8gF9s74/JFsHoNkTp2HO7WruOxm2jzsAxohxNkX0K6SUXaGC8arNoAXDwjmcUJ+xXcIoYf0Q8iXDXWgTLIwdjig/atTWXTWO3s/Vm/jJJEQxOQe8JoWYJkKuavOQY0cQUaAnq4UO59xH4QZ2rsdzqJ2VsfBWOD/0gOaK3id+8ctAnOz/g==; Domain=.costco.com; Path=/; Max-Age=7000; HttpOnly'
    );
    $respond = $this->request($url);
    // $respond = http_get($url);
    // ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0)'); 
    // $respond = file_get_contents($url);
    libxml_use_internal_errors(true);
    var_dump($respond);
    
  }
}